package com.zhkj.shixi.tvplayer.adapter;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhkj.shixi.tvplayer.R;
import com.zhkj.shixi.tvplayer.entity.ToolListEntity;

import java.util.List;

/**
 * Created by nieshuang on 19-8-15.
 */

public class ToolListAdapter extends ArrayAdapter<ToolListEntity> {
    private int mResourceId;


    public ToolListAdapter(@NonNull Context context, @LayoutRes  @IdRes int textViewResourceId, @NonNull List<ToolListEntity> objects) {
        super(context,textViewResourceId, objects);
        mResourceId =textViewResourceId;
    }

    @NonNull
    @Override

    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ToolListEntity toolListEntity =getItem(position);
        View view;
        ViewHoder viewHoder;
        if (convertView==null){
            view = LayoutInflater.from(getContext()).inflate(mResourceId,parent,false);
            viewHoder =new ViewHoder();
            viewHoder.toolImage =(ImageView) view.findViewById(R.id.subtitle_image);
            viewHoder.toolName =(TextView) view.findViewById(R.id.subtitle_name);
            view.setTag(viewHoder);
        }else {
            view =convertView;
            viewHoder =(ViewHoder) view.getTag();
        }
        viewHoder.toolImage.setImageResource(toolListEntity.getImageId());
        viewHoder.toolName.setText(toolListEntity.getItemName());
        return view;
    }
    class ViewHoder{
        ImageView toolImage;
        TextView toolName;
    }
}
